#ifndef __SP_FLASH_H__
#define __SP_FLASH_H__
#include "main.h"

#ifndef OK
#define OK		1
#endif

#ifndef ERROR
#define ERROR	0
#endif

//��ʼ��ַ
#define SP_FLASH_BASE			(FLASH_BASE)
#define SP_FLASH_ADDR_START		(SP_FLASH_BASE+(127*1024))//120
#define SP_FLASH_ADDR_END		(SP_FLASH_BASE+(128*1024))
//sector��С
#define SP_FLASH_SECTOR_SIZE	(1024*2)

void sp_flash_init(void);
void sp_flash_write_byte(uint32_t addr,uint8_t dat);
void sp_flash_write_u16(uint32_t addr,uint16_t dat);
uint16_t sp_flash_read_u16(uint32_t addr);
void sp_flash_write_buf(uint32_t addr,uint8_t *pbuf,uint32_t len);
uint8_t sp_flash_read_byte(uint32_t addr);
void sp_flash_read_buf(uint32_t addr,uint8_t *pbuf,uint32_t len);


//FLASH������
#define SP_FLASH_SAVE	0xAA
#define SP_FLASH_ERASE	0xFF
//6*2+6*2+64*4=280�ֽ�
#define SP_FLASH_ADDR_DATA_START	(SP_FLASH_ADDR_START)
#define SP_FLASH_ADDR_LOCAL_ADDR	(SP_FLASH_ADDR_DATA_START+2*0)
#define SP_FLASH_ADDR_ID			(SP_FLASH_ADDR_DATA_START+2*1)
#define SP_FLASH_ADDR_SOFT_RST		(SP_FLASH_ADDR_DATA_START+2*2)
#define SP_FLASH_ADDR_CAN_BAUD		(SP_FLASH_ADDR_DATA_START+2*3)
#define SP_FLASH_ADDR_ALM_RCV		(SP_FLASH_ADDR_DATA_START+2*4)
#define SP_FLASH_ADDR_OUT    		(SP_FLASH_ADDR_DATA_START+2*5)

#define SP_FLASH_ADDR_START2		(SP_FLASH_ADDR_DATA_START+2*10)
#define SP_FLASH_ADDR_SEN_EN(x)		(SP_FLASH_ADDR_START2+2*0+2*(x))//x:0-4
#define SP_FLASH_ADDR_LMT(x)		(SP_FLASH_ADDR_START2+2*10+2*(x))
#define SP_FLASH_ADDR_LMT_H(x)		(SP_FLASH_ADDR_START2+2*20+2*(x))
#define SP_FLASH_ADDR_CAL_N(x)		(SP_FLASH_ADDR_START2+2*30+2*(x))
#define SP_FLASH_ADDR_CAL_Y(x)		(SP_FLASH_ADDR_START2+2*40+2*(x))//x:0-20
#define SP_FLASH_ADDR_CAL_X(x)		(SP_FLASH_ADDR_START2+2*70+2*(x))
#define SP_FLASH_ADDR_CAL_DW(x)    	(SP_FLASH_ADDR_START2+2*100+2*(x))
#define SP_FLASH_ADDR_CAL_GW(x)    	(SP_FLASH_ADDR_START2+2*130+2*(x))
#define SP_FLASH_ADDR_CAL_SR(x)    	(SP_FLASH_ADDR_START2+2*160+2*(x))

#endif













